{include file="public/head"}
<div class="main">
    {include file="public/left"}
    <div class="middle">
    {include file="public/header"}
    <div class='userinfo'>
        {include file="public/userleft"}
        <ul class="use_pwd">
            <h3>{:__('密码设置')}</h3>
            <dl>
                <p>{:__('账号')}：</p>
                <span id="username"></span>
            </dl>
            <dl>
                <p>{:__('原密码')}：</p>
                <input id="old_password" type="password" class="layui-input"/>
            </dl>
            <dl>
                <p>{:__('新密码')}：</p>
                <input id="password" type="password" class="layui-input"/>
            </dl>
            <dl>
                <p>{:__('新密码确认')}：</p>
                <input id="password2" type="password" class="layui-input"/>
            </dl>
            <dl>
                <p></p>
                <button id="changepwd" class="layui-btn layui-btn-warm">{:__('确认修改')}</button>
            </dl>
        </ul>
    </div>
    {include file="public/foot"}
    </div>
    {include file="public/right"}
</div>
{include file="public/footer"}
<script>
    noLog();
    $(document).queue('user',function(){
        var userData = getLocalStorage('userData');
        var userdata = JSON.parse(userData);
        $("#username").html(userdata['username']);
    });
    
    $("#changepwd").click(function(){
        var old_password = $("#old_password").val();
        var password = $("#password").val();
        var password2 = $("#password2").val();
        if(old_password == password){
            layer.msg("{:__('原密码和新密码一致无需修改')}",{icon:2});
            return false;
        }
        if(password.length<6 || password.length>20){
            layer.msg("{:__('密码在6-20字符之间')}",{icon:2});
            return false;
        }
        if(password != password2){
            layer.msg("{:__('密码不一致')}",{icon:2});
            return false;
        }
        $.ajax({
            url:'/api/user/changeProfile',
            type:'post',
            data:{'old_password':old_password,'password':password,'token':token},
            success:function(ret){
                if(ret.code !=1 && ret.code != 401){
                    layer.msg(ret.msg,{icon:2});
                } else if(ret.code == 1){
                    layer.msg(ret.msg,{icon:1},function(){
                        $("#logout").trigger("click");
                    });
                }
            }
        });
    });
</script>